package Presentacion.Cargando;

import javax.swing.*;
import java.awt.*;

public class CargandoPantalla extends JComponent {
private JFrame frame;
private Image background;

public CargandoPantalla() {
	this.frame = new JFrame();
	frame.setUndecorated(true); //elimina los marcos del JFrame.
	updateBackground( );
	this.capturar();
	}

public void updateBackground( ) {
	try {
		Robot rbt = new Robot( );
		Toolkit tk = Toolkit.getDefaultToolkit( );
		Dimension dim = tk.getScreenSize( );
		background = rbt.createScreenCapture(
		new Rectangle(0,0,(int)dim.getWidth( ),
		(int)dim.getHeight( )));
	} catch (Exception ex) {
		ex.printStackTrace( );
		}
	}

//metodo que mete la imagen en el panel
public void paintComponent(Graphics g) {
	Point pos = this.getLocationOnScreen( );
	Point offset = new Point(-pos.x,-pos.y);
	g.drawImage(background,offset.x,offset.y,null);
	}

public void capturar() {
	this.setLayout(new BorderLayout( ));
	JLabel label = new JLabel();	
	label.setIcon(new ImageIcon("src/Presentacion/Cargando/imgCargando/cargando.gif"));
	label.setBounds(0, 0, 333, 268);	
	
	this.add("Center",label);
	frame.getContentPane( ).add("Center",this);
	frame.pack( );
	frame.setSize(80,80);
    frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	}

public void cerrar() throws Throwable {
	frame.dispose();
	this.finalize();	
	}

public static void main(String[] args) {
	CargandoPantalla bg = new CargandoPantalla();
//	bg.capturar();
	}

}